<?php

use backend\models\MallAppear;
use kartik\export\ExportMenu;
use yii\helpers\Html;
use yii\grid\GridView;
use kartik\alert\Alert;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\MallAppearSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */





$this->title = '商城提现';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="mall-appear-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php  echo $this->render('_search', ['model' => $searchModel]); ?>

    <br>
    <p>
        <?= Html::a('创建提现', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?php
    if (Yii::$app->session->get('yes')) {

    echo Alert::widget([
        'type' => Alert::TYPE_DANGER,
        'title' => '消息提示:',
        'titleOptions' => ['icon' => 'info-sign'],
        'body' => Yii::$app->session->get('message')
    ]);
    }
    ?>

    <?php
    $gridColumns = [
        'id',
        'mid',
        'uid',
        'check_id',
        'openid',
        'user.nickname',
        'amount',
        [
            'attribute' => 'status',
            'enableSorting' => false,
            'value' => 'statusValue',
            'filter' => MallAppear::attributeValue()['status']
        ],
        //'reason',
        [
            'attribute' => 'create_time',
            'value' => function($model) {
                return date('Y-m-d', $model->create_time);
            }
        ],
        [
            'attribute' => 'finish_time',
            'value' => function ($model) {
                if ($model->finish_time) {
                    return date('Y-m-d', $model->finish_time);
                } else {
                    return '';
                }
            }
        ],
    ];

    echo ExportMenu::widget([
        'dataProvider' => $dataProvider,
        'columns' => $gridColumns,
        'filename' => '提现记录-'. date('Ymd'),
        'columnSelectorOptions' => [
            'label' => '选择字段',
        ],

        'exportConfig' => [
            ExportMenu::FORMAT_TEXT => false,
            ExportMenu::FORMAT_PDF => false,
            ExportMenu::FORMAT_EXCEL_X => false,
        ],
    ]);
    ?>



    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'mid',
            'uid',
            'check_id',
            //'openid',
            [
                'attribute' => 'openid',
                'enableSorting' => false,
            ],
            'user.nickname',
            'amount',
//            'status',
            [
                'attribute' => 'status',
                'enableSorting' => false,
                'value' => 'statusValue',
                'filter' => MallAppear::attributeValue()['status']
            ],
            //'reason',
            //'create_time:datetime',
            [
                'attribute' => 'create_time',
                'value' => function($model) {
                    return date('Y-m-d', $model->create_time);
                }
            ],
            //'finish_time:datetime',
            [
                'attribute' => 'finish_time',
                'value' => function ($model) {
                    if ($model->finish_time) {
                        return date('Y-m-d', $model->finish_time);
                    } else {
                        return '';
                    }
                }
            ],
            //'check_id',

            ['class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{view} {update} {delete} {amount}',
                'buttons' => [
                    'amount' => function ($url, $model, $key) {
                        if ($model->status == 1) {
                            return Html::a('<span class="glyphicon glyphicon-btc"></span>', ['amount', 'id' => $model->id], [
                                'title' => Yii::t('yii', '提现'),
                                'aria-label' => Yii::t('yii', '提现'),
                                'data-pjax' => '0',
                                'data-method' => 'post',
                                'data-confirm' => '确定提现?',
                                'class' => 'click-on',
                            ]);
                        } else {
                            return '';
                        }
                    }
                ],
            ],
        ],
    ]); ?>
</div>

<?php
$script = <<< JS
    $(".pagination").append('&nbsp;跳转<input id="invalue" type="text" style="border-radius: 5px;outline: none;border: solid 1px #dddddd;width: 52px;height: 34px;text-align: center;" class="pane"/>页&nbsp;<button id="skip" class="btn btn-default skip ok"">确定</button>');
    
    $('#skip').click(function() {
        var page = $('#invalue').val();
        location.href = "index.php?r=mall-appear/index&page="+ page;
    }); 
JS;
$this->registerJs($script);
?>
